package org.ipp4j.core.standard;

/**
 * <p>
 * Operation value for IPP RFC.
 * 
 * @author cko
 * 
 */
public enum Operation {

	/**
	 * Invalid operation.
	 */
	OP_CUPS_INVALID(-1),

	/**
	 * Print Job
	 */
	PRINT_JOB(0x0002),

	/**
	 * Print URI
	 */
	PRINT_URI(0x0003),

	/**
	 * Validate Job
	 */
	VALIDATE_JOB(0x0004),

	/**
	 * Create Job
	 */
	CREATE_JOB(0x0005),

	/**
	 * Send Document
	 */
	SEND_DOCUMENT(0x0006),

	/**
	 * Send URI
	 */
	SEND_URI(0x0007),

	/**
	 * Cancel Job
	 */
	CANCEL_JOB(0x0008),

	/**
	 * Get Job Attributes
	 */
	GET_JOB_ATTRIBUTES(0x0009),

	/**
	 * Get Jobs
	 */
	GET_JOBS(0x000A),

	/**
	 * Get Job Attributes
	 */
	GET_PRINTER_ATTRIBUTES(0x000B),

	/**
	 * Hold Job
	 */
	HOLD_JOB(0x000C),

	/**
	 * Release Job
	 */
	RELEASE_JOB(0x000D),

	/**
	 * Restart Job
	 */
	RESTART_JOB(0x000E),

	/**
	 * Pause Printer.
	 */
	PAUSE_PRINTER(0x0010),

	/**
	 * Resume Printer.
	 */
	RESUME_PRINTER(0x0011),

	/**
	 * Purge Jobs.
	 */
	PURGE_JOBS(0x0012),

	/**
	 * Set Printer Attributes.
	 */
	SET_PRINTER_ATTRIBUTES(0x0013),

	/**
	 * Set Job Attributes.
	 */
	SET_JOB_ATTRIBUTES(0x0014),

	/**
	 * Get Printer Supported values
	 */
	GET_PRINTER_SUPPORTED_VALUES(0x0015),

	/**
	 * Create a printer subscription
	 */
	CREATE_PRINTER_SUBSCRIPTION(0x0016),

	/**
	 * Create a job subscription
	 */
	CREATE_JOB_SUBSCRIPTION(0X0017),

	/**
	 * Get subscription attributes
	 */
	GET_SUBSCRIPTION_ATTRIBUTES(0X0018),

	/**
	 * Get subscriptions
	 */
	GET_SUBSCRIPTIONS(0x0019),

	/**
	 * Renew Subscription
	 */
	RENEW_SUBSCRIPTION(0x001A),

	/**
	 * Cancel Subscription
	 */
	CANCEL_SUBSCRIPTION(0X001B),

	/**
	 * Get Notification
	 */
	GET_NOTIFICATION(0X001C),

	/**
	 * Send Notifications
	 */
	SEND_NOTIFICATIONS(0X001D),

	/**
	 * Get Resource Attributes
	 */
	GET_RESOURCE_ATTRIBUTES(0X001E),

	/**
	 * Get Resource Data
	 */
	GET_RESOURCE_DATA(0x001f),

	/**
	 * Get list of resources
	 */
	GET_RESOURCES(0x0020),

	/**
	 * Get printer support files
	 */
	GET_PRINT_SUPPORT_FILES(0x0021),

	/**
	 * Start a printer
	 */
	ENABLE_PRINTER(0x0022),

	/**
	 * Stop a printer
	 */
	DISABLE_PRINTER(0x0023),

	/**
	 * Stop printer after the current job
	 */
	PAUSE_PRINTER_AFTER_CURRENT_JOB(0x0024),

	/**
	 * Hold new Jobs
	 */
	HOLD_NEW_JOBS(0x0025),

	/**
	 * Release new Jobs
	 */
	RELEASE_HELD_NEW_JOBS(0x0026),

	/**
	 * Stop a printer
	 */
	DEACTIVATE_PRINTER(0x0027),

	/**
	 * Start a printer
	 */
	ACTIVATE_PRINTER(0x0028),

	/**
	 * Restart a printer
	 */
	RESTART_PRINTER(0x0029),

	/**
	 * Turn a printer off
	 */
	SHUTDOWN_PRINTER(0x002A),

	/**
	 * Turn a printer on
	 */
	STARTUP_PRINTER(0x002B),

	/**
	 * Reprint a job
	 */
	REPROCESS_JOB(0x002C),

	/**
	 * Cancel the current job
	 */
	CANCEL_CURRENT_JOB(0x002d),

	/**
	 * Suspend the current job
	 */
	SUSPEND_CURRENT_JOB(0x002e),

	/**
	 * Resume the current job
	 */
	RESUME_JOB(0x002f),

	/**
	 * Promote a job to print sooner
	 */
	PROMOTE_JOB(0x0030),

	/**
	 * Schedule a job to print after another
	 */
	SCHEDULE_JOB_AFTER(0x0031),

	/**
	 * Cancel-Document
	 */
	CANCEL_DOCUMENT(0x0033),

	/**
	 * Get-Document-Attributes
	 */
	GET_DOCUMENT_ATTRIBUTES(0x0034),

	/**
	 * Get-Documents
	 */
	GET_DOCUMENTS(0x0035),

	/**
	 * Delete-Document
	 */
	DELETE_DOCUMENT(0x0036),

	/**
	 * Set-Document-Attributes
	 */
	SET_DOCUMENT_ATTRIBUTES(0x0037),

	/**
	 * Cancel-Jobs
	 */
	CANCEL_JOBS(0x0038),

	/**
	 * Cancel-My-Jobs
	 */
	CANCEL_MY_JOBS(0x0039),

	/**
	 * Resubmit-Job
	 */
	RESUBMIT_JOB(0x003a),

	/**
	 * Close-Job
	 */
	CLOSE_JOB(0x003b),

	/**
	 * Identify-Printer (proposed IPP JPS3)
	 */
	IDENTIFY_PRINTER(0x003c),

	/**
	 * Validate-Document (proposed IPP JPS3)
	 */
	VALIDATE_DOCUMENT(0x003d),

	/**
	 * Reserved (0x4000)
	 */
	PRIVATE(0x4000);

	int code;
	byte[] bytes;

	Operation(int code) {
		this.code = code;
		this.bytes = new byte[] { (byte) (this.code >>> 8), (byte) (this.code) };
	}

	public static Operation valueOf(short code) {
		for (Operation operation : Operation.values()) {
			if (operation.code == code) {
				return operation;
			}
		}
		throw new IllegalArgumentException("operation code " + code
				+ " cannot be found.");
	}

	public byte[] toByteArray() {
		return this.bytes;
	}
}
